package com.nondo.rdp.finance.repository.setting.home;

import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.finance.domain.setting.home.SettingModuleSecurityOpen;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface SettingModuleSecurityOpenRepository extends JpaRepository<SettingModuleSecurityOpen, Long>, JpaSpecificationExecutor<SettingModuleSecurityOpen> {
    @Query("select a from SettingModuleSecurityOpen a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    Optional<SettingModuleSecurityOpen> findOne(@Param("id") int id);

    @Modifying
    @Query("update SettingModuleSecurityOpen set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    void deleteById(Long id);

    SettingModuleSecurityOpen save(SettingModuleSecurityOpen settingModuleSecurityOpen);

    List<SettingModuleSecurityOpen> findAllByDelFlag(String delFlag, Sort sort);
}
